/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db.dao;

import core.Course;
import java.util.List;

/**
 *
 * @author Mikael
 */
public class CourseDAO extends AbstractDAO {

    public static Course read(long primaryKey) {
        final String sql =
                "SELECT * FROM Courses WHERE id = ?";
        return jdbc.queryForObject(sql, courseMapper, primaryKey);
    }

    public static List<Course> readAll() {
        final String sql =
                "SELECT * FROM Courses";
        return jdbc.query(sql, courseMapper);
    }

    public static List<Course> readN(int startRow, int nRows) {
        final String sql =
                "SELECT * FROM Courses LIMIT ?, ?";
        return jdbc.query(sql, courseMapper, startRow, nRows);
    }

    public static int getNRows() {
        final String sql =
                "SELECT COUNT(*) FROM Courses";
        return jdbc.queryForInt(sql, DUMMY);
    }

    public static List<Course> search(Course course) {
        final String sql =
                "SELECT * FROM Courses WHERE name LIKE ? AND code LIKE ?";
        return jdbc.query(sql, courseMapper, "%" +
                course.getName() + "%", "%" +
                course.getCode() + "%");
    }
}